import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:3001', // 代理地址  localhost:5174/api/user => http://localhost:3001/api/user
        rewrite: (path) => path.replace(/^\/api/, '') // 因为后端地址不存在'/api',所以要将http://localhost:3001/api/user中的'/api'去掉
      }
    }
  }
})
